package main

import (
	"fmt"
	"github.com/garyburd/redigo/redis"  //引入redis包
)

func main()  {
	
	//连接到redis
	conn, err := redis.Dial("tcp","127.0.0.1:6379")

	if err != nil {
		fmt.Println("redis连接失败,err=",err)
		return
	}

	fmt.Println("redis连接成功,conn=",conn)

	defer conn.Close()

	//通过go向redis写入数据
	_, err = conn.Do("HMSet","user","name","test陈","age",20)
	if err != nil {
		fmt.Println("redis写入错误,err=",err)
		return
	}
	fmt.Println("写入成功")


	content, err := redis.Strings(conn.Do("HMGet","user","name","age"))
	if err != nil {
		fmt.Println("redis读取出错,err=",err)
		return
	}

	for i,v := range(content) {
		fmt.Printf("i=%d,v=%v\n",i,v)
	}
}


